#include "xTechnique.h"
#include "xLogManager.h"
#include "xPass.h"


namespace XE	
{


	xTechnique::xTechnique(const xString& name)
		:m_Name(name.c_str())
	{

	}

	xTechnique::~xTechnique()
	{
		DestoryAllPass();
	}


	void xTechnique::AddAnnotations(const xString& name,const xString& Value)
	{

	}


	xPass* xTechnique::CreatePass(const xString& name)
	{
		xPass* pass = GetPass(name);
		if(pass!=NULL)
		{
			xLogMessager::getSingleton().logMessage("Create pass err there is same name is"+name);
			return NULL;
		}
		pass = new xPass(name, this);
		m_PassVector.push_back(pass);
		return pass;
	}




	xPass*  xTechnique::GetPass(UINT i) const 
	{
		if(i>m_PassVector.size()-1)
			return NULL;
		return m_PassVector.at(i);

	}

	xPass*  xTechnique::GetPass(const xString& name)
	{
		for(size_t i = 0;i<m_PassVector.size();++i)
		{
			if(m_PassVector.at(i)->GetName()==name)
				return m_PassVector.at(i);
		}
		return NULL;

	}

	void  xTechnique::DestoryAllPass()
	{

		for(size_t i = 0;i<m_PassVector.size();++i)
		{
		        SafeDelete(m_PassVector[i])
		}
		m_PassVector.clear();
	}

	bool  xTechnique::DestoryPass( const xString& name)
	{
		for(size_t i = 0;i<m_PassVector.size();++i)
		{
			if(m_PassVector.at(i)->GetName()==name)
			{
				SafeDelete(m_PassVector[i])
				m_PassVector.erase(m_PassVector.begin()+i);
				return true;
			}
		}
		return false;

	}


}